<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Contact extends Page {

	public static $db = array(
       
	);

	public static $has_one = array(
	);

}
class MyForm extends Form {
 
   function __construct($controller, $name) {
      $fields = new FieldSet(
         new TextField('name', 'Your Name'),
         new TextField('age', 'Age'),
         new TextField('address','Address'),
         new EmailField('email','Email'),
         new TextareaField('message','Your Message')
      );
 
      $actions = new FieldSet(
         new FormAction('submit')
      );
      $vadition=new RequiredFields(
              'name',
              'age',
              'address',
              'email',
              'message'
       );
      parent::__construct($controller, $name, $fields, $actions,$vadition);
   }
 
   function forTemplate() {
      return $this->renderWith(array(
         $this->class,
         'Form'
      ));
   }
 
   function submit($data, $form) {
      // do stuff here
    /*   $name=$data['name'];
       $age=$data['age'];
       $adress=$data['address'];
       $email='email';
       $message='message';*/
        $From = 'vochicong57@gmail.com';
        $To = 'vochicong57@gmail.com';
        $Subject = 'Website Contact message';  
         $body='sfgsfgsdgs';
        $email = new Email($From, $To, $Subject,$body);
        //set template
  //      $email->setTemplate('ContactEmail');
        //populate template
    //    $email->populateTemplate($data);
        //send mail
        $email->send();


      //  $form->sessionMessage('Thanks for contacting us. We\'ll get in touch with you as soon as possible!'); 
    //    Director::redirectBack();
        //return to submitted message
      //  Director::redirect($this->Link("?success=1"));
   }
    public function Success()

   {

      return isset($_REQUEST['success']) && $_REQUEST['success'] == "1";

   } 
}

class Contact_Controller extends Page_Controller {
     function ContactForm()
    {
       
        return new MyForm($this, 'ContactForm');
    }
}
?>
